package mall.controller;

import java.util.List;
import java.util.Map;

import mall.pojo.Industry;
import mall.service.IndustryService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndustryController {
	@Autowired
	private IndustryService industryService;

	@RequestMapping("/index")
	public String listIndustry(Map<String, Object> map) {
		List<Industry> industries = industryService.listIndustry();
		map.put("listIndustry", industries);
		return "/mall/test";
	}

	@RequestMapping(value = "/addIndustry", method = RequestMethod.POST)
	public String addIndustry(@ModelAttribute("industry") Industry industry,
			BindingResult bindingResult) {
		industryService.addIndustry(industry);
		return "test";
	}

	// create new Industry blank object and pass to addindustry.jsp
	@RequestMapping(value = "/addindustry", method = RequestMethod.GET)
	public ModelAndView industry() {
		return new ModelAndView("addindustry", "command", new Industry());
	}
}
